<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>入门</title>
    <!-- 这里可以添加CSS样式文件 -->
  </head>
  <body>
     <script type="importmap">
      {
        "imports": {
          "three": "./threejs/build/three.module.js",
          "three/addons/": "./threejs/examples/jsm/"
        }
      }
    </script>
    <script type="module">
      import * as THREE from "three"; 
      import { OrbitControls } from "three/addons/controls/OrbitControls.js";

      

      const scene = new THREE.Scene();

      const camera = new THREE.PerspectiveCamera(
        75,
        window.innerWidth / window.innerHeight,
        0.1,
        1000
      );

      camera.position.set(0, 10, 10);

      const renderer = new THREE.WebGLRenderer();

      renderer.setSize(window.innerWidth, window.innerHeight);

      document.body.appendChild(renderer.domElement);

      new OrbitControls(camera, renderer.domElement);

      animate();

      function animate() {
        requestAnimationFrame(animate);

        renderer.render(scene, camera);
      }

      window.onresize = () => {
        renderer.setSize(window.innerWidth, window.innerHeight);

        camera.aspect = window.innerWidth / window.innerHeight;

        camera.updateProjectionMatrix();
      };

      // 文件地址
      const urls = [0, 1, 2, 3, 4, 5].map(
        (k) =>
          "https://z2586300277.github.io/three-editor/dist/files/scene/skyBox0/" +
          (k + 1) +
          ".png"
      );

      const textureCube = new THREE.CubeTextureLoader().load(urls);

      scene.background = textureCube;

      // 环境贴图
      const boxGeometry = new THREE.BoxGeometry(10, 10, 10);

      const boxMaterial = new THREE.MeshStandardMaterial({
        color: 0xffffff,
        envMap: textureCube,
        metalness: 1,
        roughness: 0,
      });

      const boxMesh = new THREE.Mesh(boxGeometry, boxMaterial);

      scene.add(boxMesh);
    </script>
  </body>
</html>
